<!--
 * @FileDescription: 注册
 * @Author: yijiamu
 * @Date: 2022-05-16 08:22:55
 * @LastEditors: yijiamu
 * @LastEditTime: 2022-05-16 08:22:55
 -->

<template>
  <div class="wps">
    <header class="head">
      <div class="head_logo">
        <span class="logo"></span>
      </div>
    </header>
    <main class="main">
    <div class="main_item">
      <div class="nav">
        <router-link to="/login">
          <div>
          <span class="nav_pic"></span>
          </div>
        </router-link>
        <span class="nav_title">账号注册</span>
      </div>
      <div class="login_info">
        <div class="info_item">
          <a-input v-model = "data.account" placeholder="用户名" />
<!--          <input class="info_input" v-model="data.account" placeholder="用户名" type="text">-->
        </div>
        <div class="info_item password">
          <a-button>Default Button</a-button>
<!--          <input class="info_input" v-model="data.pwd"   autocomplete="new-password">-->
          <a-input-password v-model="data.account" placeholder="input password" />
          <div class="preview">
            <span class="eye"></span>
          </div>
        </div>
        <div class="info_item password">
          <input class="info_input" v-model="data.confirmPwd" placeholder="确认密码" type="password" autocomplete="new-password">
          <div class="preview">
            <span class="eye"></span>
          </div>
        </div>
        <span class="info_password">密码为8-16位大小写字母、数字或符号3种组合</span>
        <button class="register_btn" @click="handleRegister">立即注册</button>
      </div>
      <div class="info_checkbox">
        <input type="checkbox">
        <label>
          <span class="check_img uncheck"></span>
          <span class="check_img checked"></span>
          <span class="checkbox_txt">已阅读并同意</span>
          <a class="protocal" href="http://www.wps.cn/privacy/privacyprotect/">隐私协议</a>
          <span>和</span>
          <a class="protocal" href="http://www.wps.cn/privacy/account/">在线服务协议</a>
        </label>
      </div>
    </div>
  </main>
  </div>
</template>

<script>
import { register } from '@/api/auth/api'
import { Input } from 'ant-design-vue'

export default {
  name: 'register-com',
  components: {
    'a-input-password': Input,
  },
  data(){
    return{
      data:{
        account: '',  //用户名
        pwd: '',      //密码
        confirmPwd: ''//确认密码
      },
    }
  },
/**
  * @description: 注册功能
  */
  methods: {
    async handleRegister() {
      try {
        const { account, pwd, confirmPwd } = this.data
        if (account === '' || pwd === '' || confirmPwd === '' || (account && pwd && confirmPwd === '')) {
          alert('当前输入不能为空')
          return
        } else if (pwd !== confirmPwd) {
          alert('您的确认密码与第一次输入的不一致，请重新输入')
        } else {
          const result = await register(account, pwd, confirmPwd)
          if (result?.stat === "ok"){
            await this.$router.push({ name: "login" })
          }
        }
      } catch(result) {
        alert(result?.response?.data?.msg+'，请重新输入用户名') //输出错误清空输入框
        this.data.account = ''
        this.data.pwd = ''
        this.data.confirmPwd = ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>


// 外部容器
.wps {
  position: relative;
  height: 100%;
  font-size: 14px;
  color: #535252;
  padding-top: .1px;

  // head
  .head {
    background-color: #fff;
    border-bottom: 1px solid #e9e9e9;

    // logo容器
    .head_logo {
      display: flex;
      height: 56px;
      max-width: 1180px;
      margin: 0 auto;
      align-items: center;

      // logo
      .logo {
        display: inline-block;
        margin-left: 64px;
        vertical-align: top;
        width: 88px;
        height: 22px;
        background-image: url(//ac.wpscdn.cn/account/libs/img/v1/logo.676137dd.png);
      }
    }
  }

  // 登录注册
  .main {
    overflow: hidden;
    width: 358px;
    margin: 90px auto 0;
    text-align: center;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #d8d8d8;
    position: relative;

    .main_item {
      overflow: visible;
      position: relative;
      width: 260px;
      min-height: 408px;
      margin: 0 auto;

      // 登录、注册标题容器
      .nav {
        text-align: center;
        padding-top: 37px;

        .nav_pic{
          display: inline-block;
          margin-top: 4px;
          width: 12px;
          height: 18px;
          background-position: 0 -290px;
          cursor: pointer;
          background-image: url(//ac.wpscdn.cn/account/libs/img/v1/new_login.22e5679c.png);
          position: absolute;
          left: 0;
          margin-right: 16px;
        }

        // 登录、注册标题
        .nav_title {
          font-size: 18px;
          line-height: 24px;
          color: #535252;
        }
      }

      // 注册信息
      .login_info {
        margin-top: 31px;
        display: block;
        text-align: left;
        width: 100%;
        position: relative;

        // 输入框容器
        .info_item {
          position: relative;
          // margin-top: 22px;
          width: 100%;
          background: #fff;
          border-radius: 3px;

          // 输入框
          .info_input {
            display: block;
            width: 234px;
            font-size: 14px;
            line-height: 24px;
            padding: 9px 12px;
            border: 1px solid #d8d8d8;
            border-radius: 3px;
            position: relative;
            background-color: transparent;
            background-image: url();
            font-family: inherit;
            font-weight: inherit;

            input::placeholder {
              color: #a8a8a8;
            }
          }

          .preview{
            position: absolute;
            right: 1px;
            top: 1px;
            height: 43px;
            width: 43px;
            cursor: pointer;
            text-align: center;
            line-height: 43px;

            .eye{
              display: inline-block;
              vertical-align: top;
              margin-top: 14px;
              width: 23px;
              height: 15px;
              background-position: 0 -130px;
              background-image: url(//ac.wpscdn.cn/account/libs/img/v1/signup.ab647b2c.png);
            }
          }
        }

        .password {
          margin-top: 10px;
        }

        // 注册密码要求
        .info_password{
          color: #aaa;
          display: block;
          min-height: 18px;
          margin-top: 0;
          padding-top: 10px;
          font-size: 12px;
          line-height: 18px;
        }

        // 注册按钮
        .register_btn {
          width: 260px;
          line-height: 44px;
          font-size: 14px;
          background-color: #1E86E7;
          color: #fff;
          border-radius: 4px;
          border-style: none;
          padding: 0;
          margin-top: 10px;
        }
      }

      // 协议
      .info_checkbox{
        // position: absolute;
        bottom: 44px;
        width: 100%;
        font-size: 12px;
        line-height: 18px;
        color: #aaa;
        text-align: left;
        padding-top: 10px;

        input{
          opacity: 0;
          width: 16px;
          height: 16px;
          position: absolute;
          top: 3px;
          border: 1px solid #CFCFCF;
          background-color: transparent;
          background-image: url();
          font-family: inherit;
          font-size: inherit;
          font-weight: inherit;
        }

        // 协议
        .phoneProtocal{
          position: unset;
          width: 100%;
          padding-top: 18px;
          text-align: center;
          font-size: 12px;
          line-height: 18px;
          color: #aaa;
        }

        .uncheck{
          background-position: 0 -180px;
        }

        .check_img{
          display: inline-block;
          vertical-align: top;
          width: 12px;
          height: 12px;
          margin-top: 4px;
          background-image: url(//ac.wpscdn.cn/account/libs/img/v1/signup.ab647b2c.png);
        }

        .checked{
          display: none;
          background-position: 0 -200px;
        }

        .checkbox_txt{
          margin-left: 6px;
        }

        .protocal{
          color: #9B9B9B;
          font-size: 12px;
          text-decoration: underline;
          line-height: 20px;
          outline: 0;
          cursor: pointer;
        }
      }
    }
  }
}

// 媒体查询
@media only screen and (max-width: 480px) {
  .head,
  .nav {
    display: none;
  }

  .wps .main {
    border: none;
    margin-top: 0;
    height: 100%;
    width: 100%;
    background-color: transparent;
    overflow: auto;

  }

  .main_item {
    height: auto;
  }

  .login_info {
    padding-top: 0;
  }

  .wps .main .main_item .login_info .info_item .info_input,
  .wps .main .main_item .login_info .register_btn{
    border-radius: 5px;
    margin-top: 14px;
  }

  .wps .main .main_item .login_info .info_password{
    display: block;
    margin-top: 0;
    padding: 6px 0 10px;
    font-size: 14px;
    line-height: 20px;
    min-height: 20px;
  }

  .wps .main .main_item .info_checkbox{
    position: unset;
    width: 100%;
    padding-top: 18px;
    text-align: center;
  }
}

.userInfo {
  display: flex;
  flex-direction: column;
}
</style>
